#include "TestCamera.h"
#include "QDateTime"
#include "QPainter"
#include "QPen"
#include "QFont"

TestCamera::TestCamera()
{
    this->init();
}
TestCamera::~TestCamera(){
    this->closeCamera();
}
bool TestCamera::openCamera(){
    if(this->inited == false)return false;
    this->available = true;
    return true;
}
bool TestCamera::closeCamera(){
    if(this->inited == false)return false;
    this->available = false;
    return true;
}
QImage* TestCamera::getPicture(){
    QString filename = QString::asprintf(this->imageStringFormat.toStdString().c_str(),this->imageCount);
    QImage *result = new QImage(filename);
    if(result == nullptr || result->isNull()==true){
        result = new QImage(1024,1024,QImage::Format::Format_Grayscale8);
        result->fill(QColor(50,50,50).rgb());
    }else{
        this->imageCount ++;
    }
    return result;
}
bool TestCamera::isAvailable(){
    return this->available;
}

bool TestCamera::init(){
    this->inited = true;
    return this->inited;
}

void TestCamera::setImageStringFormat(QString stringFormat){
    this->imageStringFormat = stringFormat;
    return;
}
void TestCamera::setCount(int cnt){
    if(cnt<0)return;
    this->imageCount = cnt;
    return;
}
